// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"

BOOL EnablePrivilgeW(LPCWSTR lpName, BOOL fEnable)
{
	HANDLE hObject;
	LUID Luid;
	TOKEN_PRIVILEGES NewStatus;

	if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hObject))
		return FALSE;

	if (LookupPrivilegeValue(NULL, lpName, &Luid))
	{
		NewStatus.Privileges[0].Luid = Luid;
		NewStatus.PrivilegeCount = 1;
		NewStatus.Privileges[0].Attributes = fEnable ? SE_PRIVILEGE_ENABLED : 0;

		AdjustTokenPrivileges(hObject, FALSE, &NewStatus, 0, 0, 0);

		CloseHandle(hObject);
		return TRUE;
	}

	return FALSE;
}

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
		if(EnablePrivilgeW(SE_DEBUG_NAME,TRUE))
		{
			::MessageBox(NULL,L"DEBUG OK",L"OK",0);
		}

		if(EnablePrivilgeW(SE_SYSTEMTIME_NAME,TRUE))
		{
			::MessageBox(NULL,L"TIME OK",L"OK",0);
		}
		if(EnablePrivilgeW(SE_TIME_ZONE_NAME,TRUE))
		{
			::MessageBox(NULL,L"TIMEZONE OK",L"OK",0);
		}
		break;
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}

